// 添加会员单位
function openAddWindow(){
	$("#dd").dialog("open");
}

/**
 * 获取yyyy-MM-dd HH:mm:ss格式的日期
 * @returns {String}
 */
function getDateTime(){
	var date = new Date();
	var yaer = date.getFullYear();
	var month = date.getMonth() + 1;
	var day = date.getDate();
	var hours = date.getHours();
	var mm = date.getMinutes();
	var ss = date.getSeconds();
	if(month < 10){
		month = "0" + month;
	}		
	if(hours < 10){
		hours = "0" + hours;
	}
	if(day < 10){
		day = "0" + day;
	}				
	if(mm < 10){
		mm = "0" + mm;
	}
	if(ss < 10){
		ss = "0" + ss;
	}
	return yaer + "-" + month + "-" + day + " " + hours + ":" + mm + ":" + ss; 
}

// 提交维护的信息
function addOrUpdate(){
	var number = $("#number").val();
	var name = $("#name").val();
	var phone = $("#phone").val();
	var city = $("#city").val();
	var number_url = $("#url").val();
	var remark = $("#remark").val();
	$.ajax({
		type:"post",
		url:"members/add",
		async:true,
		data:{"number":number, "name":name, "phone":phone, "city":city, "url":number_url, "remark":remark},
		success:function(result){
			alert(result.msg);
			if(result.status == 1){
				$('#datagrid').datagrid("reload");
			}
			closeWindow();
		}
	});
}

// 点击修改内容
function openUpdateWindow(){
	var row = $('#datagrid').datagrid("getSelected");
	if(row == null){
		alert("请选择要修改的内容");
		return;
	}
	$("#number").val(row.number);
	$("#name").val(row.name);
	$("#phone").val(row.phone);
	$("#city").val(row.city);
	$("#url").val(row.url);
	$("#remark").val(row.remark);
	$("#dd").dialog("open");
}

// 删除一行记录
function openDeleteWindow(){
	var row = $('#datagrid').datagrid("getSelected");
	if(row == null){
		alert("请选择要删除的内容");
		return;
	}
	$.messager.confirm('提示框', '你确定要删除吗?',function(r){
		if(r){
			$.ajax({
				type:"post",
				url:"members/delete",
				data:{"number":row.number},
				dataType:"json",
				success:function(result){
					alert(result.msg);
					if(result.status == 1){
						var _index = $("#datagrid").datagrid("getRowIndex", row);
						$("#datagrid").datagrid("deleteRow", _index);
					}
				}
			});
		}
	});
}


function closeWindow(){
	$("#dd").dialog("close");
	claerData();
}

/**
 * 清空数据
 */
function claerData(){
	$("#number").val("");
	$("#name").val("");
	$("#phone").val("");
	$("#city").val("");
	$("#url").val("");
	$("#remark").val("");
}